package com.mc2.docapp.disabilityassessmenttool.LowerLimb;

import com.mc2.docapp.disabilityassessmenttool.UpperLimb.CustDataType;
import com.mc2.docapp.disabilityassessmenttool.UpperLimb.InnerCalculations;

import io.realm.RealmObject;
import io.realm.annotations.PrimaryKey;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Lower_Limb_Mobility_Component extends RealmObject {
    @PrimaryKey
    public int id;
    private CustDataType walkingPlainSurface = new CustDataType();
    private CustDataType walkingSlope = new CustDataType();
    private CustDataType climbingStairs = new CustDataType();
    private CustDataType standingBothLegs = new CustDataType();
    private CustDataType standingAffectedLeg = new CustDataType();
    private CustDataType squatting = new CustDataType();
    private CustDataType sittingCrossLegged = new CustDataType();
    private CustDataType kneeling = new CustDataType();
    private CustDataType takingTurns = new CustDataType();
    private InnerCalculations inner_calculations = new InnerCalculations();

    /*public Lower_Limb_Mobility_Component(int id, CustDataType walkingPlainSurface, CustDataType walkingSlope, CustDataType climbingStairs, CustDataType standingBothLegs, CustDataType standingAffectedLeg, CustDataType squatting, CustDataType sittingCrossLegged, CustDataType kneeling, CustDataType takingTurns, InnerCalculations inner_calculations) {
        this.id = id;
        this.walkingPlainSurface = walkingPlainSurface;
        this.walkingSlope = walkingSlope;
        this.climbingStairs = climbingStairs;
        this.standingBothLegs = standingBothLegs;
        this.standingAffectedLeg = standingAffectedLeg;
        this.squatting = squatting;
        this.sittingCrossLegged = sittingCrossLegged;
        this.kneeling = kneeling;
        this.takingTurns = takingTurns;
        this.inner_calculations = inner_calculations;
    }*/

    public Lower_Limb_Mobility_Component strip(Lower_Limb_Mobility_Component dt) {
        return new Lower_Limb_Mobility_Component(dt.getId(), dt.getWalkingPlainSurface(), dt.getWalkingSlope(), dt.getClimbingStairs(), dt.getStandingBothLegs(), dt.getStandingAffectedLeg(), dt.getSquatting(), dt.getSittingCrossLegged(),
                dt.getKneeling(), dt.getTakingTurns(), dt.getInner_calculations());

    }

    public void calc(Lower_Limb_Mobility_Component lower_limb_mobility_component) {

        double pa = lower_limb_mobility_component.getWalkingPlainSurface().getActual_left();
        lower_limb_mobility_component.getWalkingPlainSurface().setPerc_loss_left(pa);

        double pb = lower_limb_mobility_component.getWalkingSlope().getActual_left();
        lower_limb_mobility_component.getWalkingSlope().setPerc_loss_left(pb);

        double pc = lower_limb_mobility_component.getClimbingStairs().getActual_left();
        lower_limb_mobility_component.getClimbingStairs().setPerc_loss_left(pc);

        double pd = lower_limb_mobility_component.getStandingBothLegs().getActual_left();
        lower_limb_mobility_component.getStandingBothLegs().setPerc_loss_left(pd);

        double pe = lower_limb_mobility_component.getStandingAffectedLeg().getActual_left();
        lower_limb_mobility_component.getStandingAffectedLeg().setPerc_loss_left(pe);

        double pf = lower_limb_mobility_component.getSquatting().getActual_left();
        lower_limb_mobility_component.getSquatting().setPerc_loss_left(pf);

        double pg = lower_limb_mobility_component.getSittingCrossLegged().getActual_left();
        lower_limb_mobility_component.getSittingCrossLegged().setPerc_loss_left(pg);

        double ph = lower_limb_mobility_component.getKneeling().getActual_left();
        lower_limb_mobility_component.getKneeling().setPerc_loss_left(ph);

        double pi = lower_limb_mobility_component.getTakingTurns().getActual_left();
        lower_limb_mobility_component.getTakingTurns().setPerc_loss_left(pi);


        double sumLeft = pa + pb + pc + pd + pe + pf + pg + ph + pi;

        //RIGHT CAL

        pa = lower_limb_mobility_component.getWalkingPlainSurface().getActual_right();
        lower_limb_mobility_component.getWalkingPlainSurface().setPerc_loss_right(pa);

        pb = lower_limb_mobility_component.getWalkingSlope().getActual_right();
        lower_limb_mobility_component.getWalkingSlope().setPerc_loss_right(pb);

        pc = lower_limb_mobility_component.getClimbingStairs().getActual_right();
        lower_limb_mobility_component.getClimbingStairs().setPerc_loss_right(pc);

        pd = lower_limb_mobility_component.getStandingBothLegs().getActual_right();
        lower_limb_mobility_component.getStandingBothLegs().setPerc_loss_right(pd);

        pe = lower_limb_mobility_component.getStandingAffectedLeg().getActual_right();
        lower_limb_mobility_component.getStandingAffectedLeg().setPerc_loss_right(pe);

        pf = lower_limb_mobility_component.getSquatting().getActual_right();
        lower_limb_mobility_component.getSquatting().setPerc_loss_right(pf);

        pg = lower_limb_mobility_component.getSittingCrossLegged().getActual_right();
        lower_limb_mobility_component.getSittingCrossLegged().setPerc_loss_right(pg);

        ph = lower_limb_mobility_component.getKneeling().getActual_right();
        lower_limb_mobility_component.getKneeling().setPerc_loss_right(ph);

        pi = lower_limb_mobility_component.getTakingTurns().getActual_right();
        lower_limb_mobility_component.getTakingTurns().setPerc_loss_right(pi);

        double sumRight = pa + pb + pc + pd + pe + pf + pg + ph + pi;

        lower_limb_mobility_component.setInner_calculations(new InnerCalculations(
                0,
                0,
                sumRight,
                sumLeft

        ));
    }

    private double perc(double a, double normal) {
        return ((normal - a) * 100d) / (normal + 0d);
    }

}
